<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>guestbook - active</title>

<?php
session_start();
define('IN_TG', true);
define('SCRIPT', 'active');
require_once dirname(__FILE__) . '/includes/common.inc.php';
require_once ROOT_PATH . 'includes/title.inc.php';
  global $_link;//仅用来消除本页面，变量没定义的警告
// 激活处理,判断是否有值，判断是否为40位。
if (! isset($_GET['active']) || strlen($_GET['active']) != 40) {
    _location('index.php', '访问出错！');
}
if (isset($_GET['action']) == 'OK' && isset($_GET['action']) && isset($_GET['active'])) {
    $_active = mysqli_real_escape_string(_link(), $_GET['active']);
    $_sql = "SELECT `tg_user`.`tg_active` FROM `tg_user` WHERE `tg_user`.`tg_active` = '$_active' LIMIT 1";
    _query($_link, $_sql);
    if (mysqli_affected_rows($_link) == 1) {
        $_sql = "UPDATE `tg_user` SET `tg_active` = NULL WHERE `tg_user`.`tg_active` = '$_active' LIMIT 1";
        _query($_link, $_sql);
        if (mysqli_affected_rows($_link) == 1) {
            mysqli_close($_link);
            _location('login.php', '激活成功，点击登陆！');
        } else {
            mysqli_close($_link);
            _location('register.php', '激活失败，请重新注册再激活！');
        }
    } else {
        mysqli_close($_link);
        _location('index.php', '激活失败！');
    }
}
?>
</head>
<body>
<?php
require_once ROOT_PATH . 'includes/header.inc.php';
?>
<div id="active">
		<h2>激活账户</h2>
		<p>点击下面链接激活账户</p>
		<p>
			<a
				href="http://<?php echo $_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'];?>?action=ok&amp;active=<?php echo $_GET['active'];?>">
		            http://<?php echo $_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'];?>?action=ok&amp;active=<?php echo $_GET['active'];?></a>
		</p>
	</div>
<?php
require_once ROOT_PATH . 'includes/footer.inc.php';
?>
</body>
</html>
